package entity

import (
	"context"
	"time"

	"github.com/LyricTian/gin-admin/v7/internal/app/schema"
	"github.com/LyricTian/gin-admin/v7/pkg/util/structure"
	"github.com/jinzhu/gorm"
)

// GetGroupMemberDB 获取group_member存储
func GetGroupMemberDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
	return GetDBWithModel(ctx, defDB, new(GroupMember))
}

// SchemaGroupMember group_member对象
type SchemaGroupMember schema.GroupMember

// ToGroupMember 转换为group_member实体
func (a SchemaGroupMember) ToGroupMember() *GroupMember {
	item := new(GroupMember)
	structure.Copy(a, item)
	return item
}

// GroupMember group_member实体
type GroupMember struct {
	ID        string     `gorm:"column:id;primary_key;size:36;"`
	GroupId   string     `gorm:"size:36;column:group_id;"`      // 群ID
	UserId    string     `gorm:"size:36;column:user_id;"`       // 用户ID
	ReciteDay int        `gorm:"column:recite_day;size:11;"`    // 群内背诵天数
	Status    int        `gorm:"size:11;column:status;"`        // 群内用户状态(1:正常 2:罚款)
	Creator   string     `gorm:"index;column:creator;size:36;"` // 创建者
	CreatedAt time.Time  `gorm:"column:created_at;index;"`
	UpdatedAt time.Time  `gorm:"column:updated_at;index;"`
	DeletedAt *time.Time `gorm:"column:deleted_at;index;"`
}

// ToSchemaGroupMember 转换为group_member对象
func (a GroupMember) ToSchemaGroupMember() *schema.GroupMember {
	item := new(schema.GroupMember)
	structure.Copy(a, item)
	return item
}

// GroupMembers group_member列表
type GroupMembers []*GroupMember

// ToSchemaGroupMembers 转换为group_member对象列表
func (a GroupMembers) ToSchemaGroupMembers() []*schema.GroupMember {
	list := make([]*schema.GroupMember, len(a))
	for i, item := range a {
		list[i] = item.ToSchemaGroupMember()
	}
	return list
}
